@using TaskManager.Domain.BusinessObjects
@using TaskManager.Web.Extensions
@model TaskManager.Domain.BusinessObjects.Task
@{
    ViewBag.Title = "Task Details";
}
<asp:content id="Content1" contentplaceholderid="head" runat="server">
  <script src="@Url.Content("~/Scripts/ConfirmationDialog.js")" type="text/javascript"></script>
  <script src="@Url.Content("~/Scripts/InputTextDialog.js")" type="text/javascript"></script>
  <script src="@Url.Content("~/Content/twitter-bootstrap-b37a336/js/bootstrap-tabs.js")" type="text/javascript"></script>
</asp:content>
@Html.ValidationSummaryEx(true)
<script type="text/jscript">
    $(function () {
        $('#delete').click(function () {
            ConfirmationDialog('confirmAction', "Task '@Model.Summary' will be deleted permanently",
             'Task Manager', function () {
                 $('#deleteForm').submit();
             });
            return false;
        });
        $('#complete').click(function () {
            ConfirmationDialog('confirmAction', "Would you like to close Task '@Model.Summary'?",
             'Task Manager', function () {
                 $('#completeForm').submit();
             });
            return false;
        });
        $('#reopen').click(function () {
            ConfirmationDialog('confirmAction', "Would you like to reopen Task '@Model.Summary'?",
             'Task Manager', function () {
                 $('#reopenForm').submit();
             });
            return false;
        });
        $('#comment').click(function () {
            InputTextDialog('addComment', 'Task Manager', function (text) {
                $('#userComment').val(text)
                $('#commentForm').submit();
            });

            return false;
        });
    });
</script>
<div id="confirmAction" class="modal hide">
    <div class="modal-header">
        <a href="#" class="close">&times;</a>
        <h3>
            Task Manager</h3>
    </div>
    <div class="modal-body">
        <p>
            Text</p>
    </div>
    <div class="modal-footer">
        <input type="button" class="btn primary" id="confirmAction-btn1" value="OK">
        <input type="button" class="btn secondary" id="confirmAction-btn2" value="Cancel">
    </div>
</div>
<div id="addComment" class="modal hide">
    <div class="modal-header">
        <a href="#" class="close">&times;</a>
        <h3>
            Task Manager</h3>
    </div>
    <div class="modal-body">
        <div class="input">
            <textarea class="xxlarge" name="textarea" id="text" rows="3"></textarea>        
        </div> 
    </div>
    <div class="modal-footer">
        <input type="button" class="btn primary" id="addComment-btn1" value="OK">
        <input type="button" class="btn secondary" id="addComment-btn2" value="Cancel">
    </div>
</div>
<div class="well">
    <div class="row">
        <div class="span1" style="width: auto">
            @Html.ActionLink("Edit", "Edit", new { id = Model.Id, tab = ViewBag.Tab }, new { @class = "btn" })
        </div>
        @if (Model.State == TaskState.InProgress)
        {
            <div class="span1" style="width: auto">
                @using (Html.BeginForm("Complete", "Task", new {tab = ViewBag.Tab}, FormMethod.Post, new { id = "completeForm" }))
                {
                    @Html.Hidden("id", Model.Id)
                    <input type="submit" class="btn" value="Complete" id="complete" />
                }
            </div>
            <div class="span1" style="width: auto">
                @using (Html.BeginForm("AddComment", "Task", new { tab = ViewBag.Tab }, FormMethod.Post, new { id = "commentForm" }))
                {
                    @Html.Hidden("id", Model.Id)
                    @Html.Hidden("userComment")
                    <input type="submit" class="btn" value="Comment" id="comment" />
                }
            </div>
        }
        @if (Model.State == TaskState.NotStarted)
        {
            <div class="span1" style="width: auto">
                @using (Html.BeginForm("Start", "Task", new { tab = ViewBag.Tab }, FormMethod.Post, new { id = "startForm" }))
                {
                    @Html.Hidden("id", Model.Id)
                    <input type="submit" class="btn" value="Start" id="start" />
                }
            </div>
        }
        @if (Model.State == TaskState.Finished)
        {
            <div class="span1" style="width: auto">
                @using (Html.BeginForm("Reopen", "Task", new { tab = ViewBag.Tab }, FormMethod.Post, new { id = "reopenForm" }))
                {
                    @Html.Hidden("id", Model.Id)
                    <input type="submit" class="btn" value="Reopen" id="reopen" />
                }
            </div>
            <div class="span1" style="width: auto">
                @using (Html.BeginForm("Delete", "Task", new { tab = ViewBag.Tab }, FormMethod.Post, new { id = "deleteForm" }))
                {
                    @Html.Hidden("id", Model.Id)
                    <input type="submit" class="btn" value="Delete" id="delete" />
                }
            </div>
        }
    </div>
</div>
<div class="row" style="min-width: 840px">
    <div class="span7">
        @using (Html.BeginForm())
        {
            <fieldset>
                @Html.NameAndValue("Summary", @Model.Summary)
                @Html.NameAndValue("Description", @Model.Description)
                @Html.NameAndValue("State", Html.DisplayFor(m => m.State).ToString())
                @Html.NameAndValue("Project", @Model.Project.Name)
                @Html.NameAndValue("Priority", @Model.Priority.ToString())
            </fieldset>
        }
    </div>
    <div class="span7" style="float:right">
        @using (Html.BeginForm())
        {
            <fieldset>
                @Html.NameAndValue("Owner", @Model.Owner)
                @Html.NameAndValue("Assignee", @Model.Assignee)
                @Html.NameAndValue("Created", @Model.Created.ToString())

                @if (@Model.State == TaskState.Finished)
                {
                    @Html.NameAndValue("Closed", @Model.Updated.ToString())
                }
                else
                {
                    @Html.NameAndValue("Last Modified", @Model.Updated.ToString())
                }
            </fieldset>
        }
    </div>
</div>

<ul class="tabs" data-tabs="tabs">
  <li class="active">
    <a href="#comments">Comments</a>
  </li>
  <li>
    <a href="#logs">Logs</a>
  </li>
</ul>

<div class="tab-content" style="width:800px">
    <div class="tab-pane active" id="comments">
        <div id="commentList">
            @Html.Action("Comments", new { id = Model.Id })
        </div>        
    </div>
    <div class="tab-pane" id="logs">
        <div id="logList">
            @Html.Action("Log", new { id = Model.Id })
        </div>        
    </div>
</div>